<?php

namespace App\Containers\AppSection\Questionnaire\Tasks;

use App\Containers\AppSection\Questionnaire\Data\Repositories\FormRepository;
use App\Containers\AppSection\Questionnaire\Models\Form;
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class CreateFormTask extends Task
{
    protected FormRepository $repository;

    public function __construct(FormRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run(array $data): Form
    {
        try {
            return $this->repository->create($data);
        } catch (Exception $exception) {
            throw new CreateResourceFailedException();
        }
    }
}
